
Public Class DAOKhachHang
    Public Shared Function KhachHang_Load() As DataTable
        Return DataProvider.LoadTable("Select * from KhachHang")
    End Function

    Public Shared Sub KhachHang_Insert(ByVal kh As DTOKhachHang)
        'Dim Npara As Integer = 5
        'Dim sql As String = "usp_InsertKHACHHANG"
        'Dim name As String() = New String(Npara - 1) {}
        'Dim value As Object() = New Object(Npara - 1) {}
        'name(0) = "@TenKH"
        'name(1) = "@ngaysinh"
        'name(2) = "@diachi"
        'name(3) = "@dienthoai"
        'name(4) = "@makh"

        'value(0) = kh.TenKH
        'value(1) = kh.NgaySinh
        'value(2) = kh.DiaChi
        'value(3) = kh.DienThoai
        'value(4) = kh.MaKH

        'DataProvider.ExecuteNonQueryPara(sql, name, value, Npara)
        Dim sql As String = String.Format("insert into KHACHHANG(TenKH,NgaySinh,DiaChi,DienThoai) values (N'{0}','{1}','{2}','{3}')", kh.TenKH, kh.NgaySinh, kh.DiaChi, kh.DienThoai)
        DataProvider.ExecuteNonQuery(sql)
    End Sub

    Public Shared Sub KhachHang_Update(ByVal kh As DTOKhachHang)
        'Dim Npara As Integer = 5
        'Dim sql As String = "usp_updatekHACHHANG"
        'Dim name As String() = New String(Npara - 1) {}
        'Dim value As Object() = New Object(Npara - 1) {}
        'name(0) = "@tenkh"
        'name(1) = "@ngaysinh"
        'name(2) = "@diachi"
        'name(3) = "@dienthoai"
        'name(4) = "@makh"

        'value(0) = kh.TenKH
        'value(1) = kh.NgaySinh
        'value(2) = kh.DiaChi
        'value(3) = kh.DienThoai
        'value(4) = kh.MaKH
        'DataProvider.ExecuteNonQueryPara(sql, name, value, Npara)
        Dim sql As String = String.Format("update KHACHHANG set TenKH = N'{0}', NgaySinh = '{1}', DiaChi = N'{2}', DienThoai = '{3}' where MaKH = '{4}'", _
                                          kh.TenKH, kh.NgaySinh, kh.DiaChi, kh.DienThoai, kh.MaKH)
        DataProvider.ExecuteNonQuery(sql)
    End Sub
    Public Shared Sub KhachHang_Delete(ByVal kh As DTOKhachHang)
        Dim sql As String = String.Format("delete KhachHang where MAKH = '{0}'", kh.Makh)
        DataProvider.ExecuteNonQuery(sql)
    End Sub
End Class